package com.example.myapplication.activity;

import android.view.View;
import android.widget.TextView;

import com.example.myapplication.BaseActivity;
import com.example.myapplication.R;
import com.example.myapplication.adp.CustomBannerHolder;
import com.example.myapplication.database.SellItem;
import com.example.myapplication.util.DbUtils;
import com.example.myapplication.util.ToastUtil;
import com.ms.banner.Banner;

public class SellItemDetailAty extends BaseActivity {
    private TextView tvTitle,itemTitle,itemDes,itemPrice,btBuy;
    private Banner banner;
    private SellItem sellItem;
    @Override
    protected void logicStart() {
        sellItem= (SellItem) getIntent().getSerializableExtra("data");

        setUi();
    }

    private void setUi() {
        tvTitle.setText("物品详情");
        itemTitle.setText(sellItem.getTitle());
        itemDes.setText(sellItem.getDes());
        itemPrice.setText("￥"+sellItem.getPrice());
        banner.setPages(sellItem.getPhotos(),new CustomBannerHolder())
                .start();

    }

    @Override
    protected void initView() {
        banner=findViewById(R.id.banner);
        tvTitle=findViewById(R.id.tvTitle);
        itemTitle=findViewById(R.id.itemTitle);
        itemDes=findViewById(R.id.itemDes);
        itemPrice=findViewById(R.id.itemPrice);
        btBuy=findViewById(R.id.btBuy);

    }

    @Override
    protected void setListener() {
        super.setListener();
        btBuy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (sellItem.getSellerId()==DbUtils.getLoginUser().getId()){
                    ToastUtil.toast("不能购买自己的商品");
                    return;
                }
                //todo 购买

            }
        });
    }

    @Override
    public int getLayoutId() {
        return R.layout.aty_sellitem_detail;
    }
}
